
# IP: 211.103.136.244
# port: 7061
# user: student
# pwd: iHRM_student_2022
# database: test_db


# 导包
import pymysql

# 创建连接对象
conn = pymysql.connect(host="211.103.136.244",
                       port=7061,
                       user="student",
                       password="iHRM_student_2022",
                       database="test_db",
                       charset="utf8")

# 创建游标
cursor = conn.cursor()

# 执行sql语句
# 需求：将图书表中【水浒传】的阅读量设置为20000
# sql = "update t_book set `read`=20000 where id=4;"
# 插入图书title='东游记'， pub_date=1990-01-01
# sql = "insert into t_book(title, pub_date) values('东游记', '1990-01-01');"
# 删除插入【东游记】图书信息
sql = "delete from t_book where title='东游记';"


# 查询与非查询：
# ① sql语句不一样
# ② 非查询操作需要涉及事务：
#  正常：提交事务 conn.commit()
#  异常：回滚事务 conn.rollback()

cursor.execute(sql)
conn.commit()
print(cursor.rowcount)

# 关闭游标
cursor.close()

# 关闭连接
conn.close()

